<?php ob_start(); 
session_start(); // on relaye la session 
if(isset($_SESSION["is_registered"]) && $_SESSION["is_registered"] == "registered"){
		$enregistrer = $_SESSION["is_registered"];
}else{
	header("location:../../../menu.php"); // redirection en cas d'echec
}
	require_once('../../../Connections/microassur.php');
 	require_once('../../../utils/fonctions.php'); 
	require_once('../inclure.php');
	$message = ''; ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$editFormAction = $_SERVER['PHP_SELF'];
if(isset($_POST['Code_table'])){
	$existe = existeChampAutre($database_microassur, $microassur, 'dictionnaire', 'Code_table', GetSQLValueString($_POST['Code_table'], "text"));
}
//$ver = (!veriflibelle1('Code_table')); var_dump($ver);
if(isset($_POST['Code_table']) && empty($_POST['Code_table'])){
	$message = colorer("Vous devez saisir le CODE.","false");
}elseif(isset($_POST['Code_table']) && !veriflibelle1('Code_table') && caracteres_interdits($_POST['Code_table'])==1){
	$message = colorer("Le code saisi comporte des caractères spéciaux interdits.","false");
}elseif(isset($_POST['Libelle_table']) && empty($_POST['Libelle_table'])){
	$message = colorer("Vous devez saisir le LIBELLE.","false");
}elseif(isset($_POST['Libelle_table']) && caracteres_interdits($_POST['Libelle_table'])==1){
	$message = colorer("Le libellé saisi comporte des caractères spéciaux interdits.","false");
}elseif(isset($existe) && $existe=='1'){
	$message = colorer( "Ce dictionnaire existe déjà","false");
}// Fin if($existe=='1')
else { // Else if($existe=='1')
	if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
	  $insertSQL = sprintf("INSERT INTO dictionnaire (Identifiant_table, Code_table, Libelle_table, Type_table) VALUES (%s, %s, %s, %s)",
						   GetSQLValueString($_POST['Identifiant_table'], "int"),
						   GetSQLValueString($_POST['Code_table'], "text"),
						   GetSQLValueString($_POST['Libelle_table'], "text"),
						   GetSQLValueString($_POST['Type_table'], "text"));
	  //var_dump($_POST);				   
	  mysql_select_db($database_microassur, $microassur);
	  mysql_query("START TRANSACTION");
	  $Result1 = mysql_query($insertSQL, $microassur) or die(mysql_error());
	  if($Result1){ mysql_query("commit");
		  	$message = colorer( "Le dictionnaire est créé","true");
			unset($_POST);		
		}
	  else
	  	{ 
			mysql_query("rollback"); $message = colorer( "Contacter la DSI, erreur création dictionnaire","false");
		}
	}
}  // End Else if($existe=='1')

$maxRows_rsdico = 10;
$pageNum_rsdico = 0;
if (isset($_GET['pageNum_rsdico'])) {
  $pageNum_rsdico = $_GET['pageNum_rsdico'];
}
$startRow_rsdico = $pageNum_rsdico * $maxRows_rsdico;

mysql_select_db($database_microassur, $microassur);
$query_rsdico = "SELECT * FROM dictionnaire";
//$query_limit_rsdico = sprintf("%s LIMIT %d, %d", $query_rsdico, $startRow_rsdico, $maxRows_rsdico);
$query_limit_rsdico = $query_rsdico;
$rsdico = mysql_query($query_limit_rsdico, $microassur) or die(mysql_error());
$row_rsdico = mysql_fetch_assoc($rsdico);

if (isset($_GET['totalRows_rsdico'])) {
  $totalRows_rsdico = $_GET['totalRows_rsdico'];
} else {
  $all_rsdico = mysql_query($query_rsdico);
  $totalRows_rsdico = mysql_num_rows($all_rsdico);
}
$totalPages_rsdico = ceil($totalRows_rsdico/$maxRows_rsdico)-1;

$queryString_rsdico = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rsdico") == false && 
        stristr($param, "totalRows_rsdico") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rsdico = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rsdico = sprintf("&totalRows_rsdico=%d%s", $totalRows_rsdico, $queryString_rsdico);


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=8" />
			<title><?php echo $titleGen ?></title>
			<link rel="stylesheet" type="text/css" href="../../../css/main.css" />
            <link rel="stylesheet" type="text/css" href="list.css" />
			<!--[if IE 7]>
            	<link rel="stylesheet" type="text/css" href="../../../css/ie7.css" />
            	<link rel="stylesheet" type="text/css" href="form_ie7.css" />
            <![endif]-->
	</head>
<body>
			<div id="sf_menu1">
				<h3>Administration</h3>
<?php 
	if( isset($message) && !empty($message) ){
		echo $message;
	} 
	$nommodule="Dictionnaire";
	$nommodule2="Liste des dictionnaires";
	$nom_module_saisie="Ecran saisie";
?>
			</div>
			<div class="cleared"></div>
		<div class="corps1">
			<!--/***************************************/-->
			<div class="imgleft"></div>
			<div class="imgmiddle">
			<div class="btn"><span class="btnleft"></span><span class="btnmiddle"><h5><?php echo $nommodule; ?></h5></span><span class="btnright"></span></div>
			<div class="btn1"><span class="btnleft"></span><span class="btnmiddle"><h5><?php echo $nommodule2; ?></h5></span><span class="btnright"></span></div>
			<div class="cleared"></div>
                <table class="tab_list bordh">
					<tr id="niv1">
						  <td class="col1">CODE</td>
						  <td class="col2">LIBELLE</td>
						  <td class="col3">TYPE</td>
					</tr>
                </table>
				<div class="content_table">
					<table class="tab_list">
						<?php $i=1; do 	{ ?>
						<?php if ($totalRows_rsdico > 0) { // Show if recordset not empty ?>
						  <tr <?php if($i%2==0) echo 'class="colorligne"'; ?> >
							<td class="col1"><a href="moddictionnaire.php?Identifiant_table=<?php echo $row_rsdico['Identifiant_table']; ?>"><?php echo $row_rsdico['Code_table']; ?></a></td>
							<td class="col2"><a href="moddictionnaire.php?Identifiant_table=<?php echo $row_rsdico['Identifiant_table']; ?>"><?php echo $row_rsdico['Libelle_table']; ?></a></td>
							<td class="col3"><a href="moddictionnaire.php?Identifiant_table=<?php echo $row_rsdico['Identifiant_table']; ?>"><?php echo $row_rsdico['Type_table']; ?></a></td>
						  </tr>
							<?php } // Show if recordset not empty ?>

						  <?php $i++; } while ($row_rsdico = mysql_fetch_assoc($rsdico)); ?>
					</table>
				</div>
			</div>
			<div class="imgright"></div>
		<div class="cleared"></div>
		<!--/***************************************/-->
		<div id="br"></div>

					<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
			<div class="imgleft"></div>
			<div class="imgmiddle">
				<div class="btn"><span class="btnleft"></span><span class="btnmiddle"><h5><?php echo $nommodule; ?></h5></span><span class="btnright"></span></div>
				<div class="btn1"><span class="btnleft"></span><span class="btnmiddle"><h5><?php echo $nom_module_saisie; ?></h5></span><span class="btnright"></span></div>
					<div class="formulaire">
							<table class="tabform">
								<tr>
									<td>CODE</td>
									<td><input class="resize_1" type="text" name="Code_table"  maxlength="5" value="<?php echo remind_text('Code_table'); ?>" size="32" /></td>
								</tr>
								<tr>
									<td>LIBELLE</td>
									<td><input type="text"  maxlength="30" name="Libelle_table" value="<?php echo remind_text('Libelle_table'); ?>" size="32" /></td>
								</tr>
								<tr>
									<td>TYPE</td>
									<td>
										<select name="Type_table">
											<option value="T" <?php echo remind_select('Type_table', 'T') ?>>Technique</option>
											<option value="M" <?php echo remind_select('Type_table', 'M') ?>>M&eacute;tier</option>
										</select>
									</td>
								</tr>
							</table>
					</div>
			</div>
			<div class="imgright"></div>				
				<div class="cleared"></div>
				
					<div class="bt1"><a href="<?php echo $retour; ?>"><span class="btleft"></span><span class="btmiddle">Retour</span><span class="btright"></span></a></div>
					<div class="bt"><span class="btleft"></span><input type="submit" name="Creer" value="Créer" class="resizeall btmiddle"/><span class="btright"></span></div>
					
				<div class="cleared"></div>
  <input type="hidden" name="Identifiant_table" value="" />
  <input type="hidden" name="MM_insert" value="form1" />
</form>
 </div>
</body>
</html><?php ob_end_flush();?>
<?php
mysql_free_result($rsdico);
?>